App({
  globalData: {
    userInfo: null,
    currentLearningBook: null
  },
  onLaunch() {
    // 检查登录状态
    wx.checkSession({
      success: () => {
        const userInfo = wx.getStorageSync('userInfo')
        if (userInfo) {
          this.globalData.userInfo = userInfo
        }
      },
      fail: () => {
        wx.removeStorageSync('userInfo')
        wx.removeStorageSync('isLogin')
      }
    })
  },
  onShow() {
    // 全局登录拦截
    const pages = getCurrentPages();
    const currentPage = pages[pages.length - 1];
    // const currentRoute = currentPage ? currentPage.route : '';
    const isLogin = wx.getStorageSync('isLogin');
    console.log('isLogin', isLogin)
    if (!isLogin) {
      wx.reLaunch({
        url: '/pages/login/login'
      });
    }
  },
  setCurrentLearningBook(book) {
    this.globalData.currentLearningBook = book;
  }
}) 